package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.IWmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private IWmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestBody MultipartFile multipartFile){
        ResponseResult responseResult = null;
        try {
            responseResult = wmMaterialService.uploadPicture(multipartFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return responseResult;
    }

    /**
     * 查询素材列表,page页码,size每页条数,isCollection是否收藏
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listByPage(@RequestBody WmMaterialDto dto){
        ResponseResult responseResult = wmMaterialService.listByPage(dto);
        return responseResult;
    }

    /**
     * 删除图片
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult deletePicture(@PathVariable Integer id){
        return  wmMaterialService.deletePicture(id);
    }

    /**
     * 取消收藏接口
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Integer id){
        return wmMaterialService.cancelCollect(id);
    }

    /**
     * 收藏接口
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        return wmMaterialService.collect(id);
    }
}
